package com.fyp.ptma.controllers;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

import com.fyp.ptma.gcm.ApiKeyInitializer;
import com.fyp.ptma.gcm.Sender;

public class ServletContextListener implements
		javax.servlet.ServletContextListener {

	public static Sender SENDER;

	@Override
	public void contextDestroyed(ServletContextEvent ctxEvent) {
		
		System.out.println("ServletContextListener contextDestroyed");
	}

	@Override
	public void contextInitialized(ServletContextEvent ctxEvent) {
		SENDER = newSender(ctxEvent.getServletContext());
		System.out.println("ServletContextListener contextInitialized");

	}

	protected Sender newSender(ServletContext context) {
		String key = (String) context
				.getInitParameter(ApiKeyInitializer.ATTRIBUTE_ACCESS_KEY);
		return new Sender(key);
	}

}
